<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
    public function index(){
    	//后台会员项分页
        $user = M('user'); // 实例化question对象
        $count = $user->count();// 查询满足要求的总记录数 
        //var_dump($count); //string '14' (length=2)
        $Page = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(4)
        $show = $Page->show();// 分页显示输出 show方法生成页码
        //echo $show; //<< 1234 >> http://127.0.0.1/yuephp/bbs1/index.php/Home/Index/index/p/3.html
        $this->assign('page',$show);
        //firstRow-0,4,8;listRows-4 从第(8)条后面取多少(4)条 根据传的P生成不一样的值
        var_dump($Page->firstRow,$Page->listRows);



    	//查询user表所有数据  按条分页
    	$sql = "select * from user limit ".$Page->firstRow.','.$Page->listRows;
    	$users = M()->query($sql);
    	//$users = M('user')->select();
    	//var_dump($users);exit;

    	$this->assign('users',$users);
        $this->display();
    }

    public function memberstop()
    {
    	/*var_dump($_POST);
    	array (size=1)
  			'uid' => string '1'*/
  		$uid = I('post.uid'); //异步post的uid等于被点击要停用的用户id
  		/*var_dump($uid);
  		$sql = "select * from user where id='{$uid}'";
  		$sql = M()->query($sql);
  		$sql = current($sql);
  		$sql['stop']=1;
  		var_dump($sql);*/
  		//M('user')->where("id={$uid}")->save($sql);
  		//
  		//另 M('user')->where(array('id'=>$uid))->save(array('stop'=>1)
  		M('user')->where("id={$uid}")->save(array('stop'=>1));
    }

    public function memberstart()
    {
    	/*var_dump($_POST);
    	array (size=1)
  			'uid' => string '1'*/
  		$uid = I('post.uid'); //异步post的uid等于被点击要停用的用户id
  		/*var_dump($uid);
  		$sql = "select * from user where id='{$uid}'";
  		$sql = M()->query($sql);
  		$sql = current($sql);
  		$sql['stop']=0;
  		var_dump($sql);*/
  		//M('user')->where("id={$uid}")->save($sql);
  		//
  		//另 M('user')->where(array('id'=>$uid))->save(array('stop'=>0)
  		$res = M('user')->where("id={$uid}")->save(array('stop'=>0));
  		if($res){
  			$arr = array(
    			'error'=>0,
    			'info'=>'已启用'
    			);
    		echo json_encode($arr);
    		exit;

    	}else{
    		$arr = array(
    			'error'=>1,
    			'info'=>'启用失败'
    			);
    		echo json_encode($arr);
    		exit;
    	}
    }





}



/*$uid = I('post.uid');

    	if(M('user')->where(array('id'=>$uid))->save(array('stop'=>1))){
    		$arr = array(
    			'error'=>0,
    			'info'=>'已停用'
    			);
    		echo json_encode($arr);
    		exit;

    	}else{
    		$arr = array(
    			'error'=>1,
    			'info'=>'停用失败'
    			);
    		echo json_encode($arr);
    		exit;
    	}*/